﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

using Entities;
using DAL;
using Entities;
using System.Collections.Generic;



public partial class SMSAPI : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

          
            bool result = true;
            if (Request.QueryString["CheckPointID"] != null)
            {
                DAL.CheckPointDALs checkpointdals = new DAL.CheckPointDALs();
                Entities.CheckPoint point = checkpointdals.GetByID(Convert.ToInt16(Request.QueryString["CheckPointID"]));

                if (point != null)
                {
                    //读取用户组
                    DAL.GroupUserDALs groupuserdals = new DAL.GroupUserDALs();
                    IList<GroupUser> lst = groupuserdals.GetByGroupId(point.GroupID);
                    IList<User> users = new List<User>();
                    foreach (GroupUser groupuser in lst)
                    {
                        DAL.UserDALs userdal = new DAL.UserDALs();
                        User user = userdal.GetByID(groupuser.UserID);
                        users.Add(user);
                    }

                    if (Convert.ToBoolean(point.IsSendEmail))
                    {
                        BLL.Message.IMessage message = new BLL.Message.EmailMessage();
                        message.SendMessage(users, point.F2, point.SendMessage,null);

                    }
                    if (Convert.ToBoolean(point.IsSendSMS))
                    {
                        BLL.Message.IMessage message = new BLL.Message.FetionMessage(false);
                        message.SendMessage(users, point.F2, point.SendMessage,null);
                    }
                }
                else
                    result = false;
            }
            else
                result = false;
            //if (Request.QueryString["mobiles"] != null && Request.QueryString["message"] != null)
            //{
            //    string message = Request.QueryString["message"];
            //    string[] mobiles = Request.QueryString["mobiles"].Split(",".ToCharArray());
            //    foreach (string mobile in mobiles)
            //    {
            //        if (Regex.Match(mobile.Trim(), @"[\d]{11}").Success)
            //        {
            //            if (!BLL.Message.CSFetionSingleton.SendSMS(mobile, message))
            //                result = false;
            //        }
            //    }

            //}
            //else
            //    result = false;
            Response.Write(result.ToString());
            Response.End();
        }
    }
}
